package com.itheima.train.service.impl;

import java.util.List;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.train.common.util.ObjectUtils;
import com.itheima.train.dao.CZYGroupDao;
import com.itheima.train.domain.CZYGroupDO;
import com.itheima.train.domain.CZYGroupDTO;
import com.itheima.train.domain.CZYGroupQuery;
import com.itheima.train.service.CZYGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CZYGroupServiceImpl implements CZYGroupService {

	@Autowired
	private CZYGroupDao groupDao;

	/**
	 * 查询组列表
	 * @param adminId 管理员id
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<CZYGroupDTO> findGroupListByAdminId(Long adminId) throws Exception {
		List<CZYGroupDO> groupList = groupDao.findGroupListByAdminId(adminId);
		List<CZYGroupDTO> resultGroups = ObjectUtils.convertList(
				groupList, CZYGroupDTO.class);
		return resultGroups;

	}

	@Override
	public PageInfo<CZYGroupDTO> findGroupListPage(CZYGroupQuery query) throws Exception{
		PageHelper.startPage(query.getPageNo(), query.getPageSize());
		List<CZYGroupDO> list =groupDao.findGroupListPage(query.getCreateBy());
		List<CZYGroupDTO> resultGroups = ObjectUtils.convertList(
				list, CZYGroupDTO.class);
		PageInfo<CZYGroupDTO> result = new PageInfo<CZYGroupDTO>(resultGroups);
		return result;
	}
}
